<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
            jQuery.validator.addMethod("file_upload2_valid", function(value, element, param) {
				var messages = '';
                var returnVal = true;
				if(!(($('#song_id').find('input').length > 1 && $('input[name="is_relate_song"]:checked').val() == 1) || $('input[name="is_relate_song"]:checked').val() == 0)){
					messages += "- <?php echo lang('song_relate_default_over');?>\n";
				}				
				if(messages){
					jQuery.validator.messages.file_upload2_valid = messages.substr(2,(messages.length-2));
					returnVal = false;	
				}							
				return returnVal;
           	}, jQuery.validator.messages.file_upload2_valid);
													
            $("#Form").validate({
				ignore: "",
                rules: {
					video_type_id: "required",
					media_type_id: "required",
					letters: "required",
					video_name: "required",
					file_upload2: {
						file_upload2_valid:true
					},	
					video_tag: "required"
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }
					if(queueSize2 > 0){
						$('#file_upload2').uploadifyUpload();
					} else { success_file2 = true; }									
					var interval = setInterval(function() {
					    if (success_file && success_file2) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					video_type_id: "<?php echo lang('video_type');?>",
					media_type_id: "<?php echo lang('media_type');?>",
					letters: "<?php echo lang('letters');?>",
					video_name: "<?php echo lang('video_name');?>",
					video_tag: "<?php echo lang('video_tag');?>"			
                }
            });	
			
            /*Images Upload*/
            var queueSize = 0;		
            var imgname= new Array();
			var success_file = false;					
            $('#file_upload').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store',
					    name: 'uploadify_store',
						value: imgname
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file=true;
                },			
                'onSelectOnce' : function (event,data) {
                    queueSize = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize = data.fileCount;
                }						
            });	

            /*File Upload*/
            var queueSize2 = 0;		
            var imgname2= new Array();
			var success_file2 = false;					
            $('#file_upload2').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.mp4;*.MP4',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname2.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store2',
					    name: 'uploadify_store2',
						value: imgname2
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file2=true;
                },			
                'onSelectOnce' : function (event,data) {
                    queueSize2 = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize2 = data.fileCount;
                }						
            });
			//ColorBox Iframe
			$('.search_tools').colorbox({iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});	
			
			//ColorBox Image
			$('a[rel="gallery"]').colorbox();						
			
			$('input[name="is_relate_song"]').click(function(){
				if($(this).val() == 1){
					$('.is_not_relate_song').hide();
					$('.is_relate_song').show();	
				} else {
					$('.is_relate_song').hide();
					$('.is_not_relate_song').show();					
				}
			});
			
			/*Check Video Type (1 = Music Video,4 = Concert, 8 = Karaoke)*/
			$('#video_type_id').change(function(){
				if(!($(this).val() == 1 || $(this).val() == 4 || $(this).val() == 8)){
					$('#genre_id').closest('tr').hide();
				} else {
					$('#genre_id').closest('tr').show();
				}
			});
			
			//DateTime Picker
			$('.datetime').datetimepicker({
				dateFormat:'dd/mm/yy',
				timeFormat:'hh:mm',
				separator:' ',
				changeMonth : true,
				changeYear : true,
				yearRange: '-100y:c+nn',
				maxDate: '-1d',
				showHour: true,		
				showMinute: true,
				showTime: true		
			});								
        });
    })(jQuery);
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" <?php echo ($dataResult->is_publish == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" <?php echo ($dataResult->is_publish == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('video_publish_date');?>
							</th>
							<td>
								<input type="text" name="video_publish_date" id="video_publish_date" class="medium-text datetime" value="<?php echo convertDatetimeToString($dataResult->video_publish_date);?>" readonly="readonly"/>
							</td>
						</tr>											
						<tr>
							<th scope="row"><?php echo lang('video_type');?></th>
							<td>
								<select id="video_type_id" name="video_type_id" class="medium-text">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataVideoType as $value):?>
										<option value="<?php echo $value->video_type_id;?>" <?php echo ($dataResult->video_type_id == $value->video_type_id ? 'selected="selected"':'');?>><?php echo $value->video_type_name;?></option>
									<?php endforeach;?>
								</select>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('media_type');?></th>
							<td>
								<select id="media_type_id" name="media_type_id" class="medium-text">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataMediaType as $value):?>
										<option value="<?php echo $value->media_type_id;?>" <?php echo ($dataResult->media_type_id == $value->media_type_id ? 'selected="selected"':'');?>><?php echo $value->media_type_name;?></option>
									<?php endforeach;?>
								</select>
							</td>
						</tr>
						<tr <?php echo (!in_array($dataResult->genre_id,array(1,4,8)) ? 'style="display:none;"':'');?>>
							<th scope="row"><?php echo lang('genre');?></th>
							<td>
								<select id="genre_id" name="genre_id" class="medium-text">
									<option value=""><?php echo lang('select_option');?></option>
									<?php foreach($dataGenre as $value):?>
										<option value="<?php echo $value->genre_id;?>" <?php echo ($dataResult->genre_id == $value->genre_id ? 'selected="selected"':'');?>><?php echo $value->genre_name;?></option>
									<?php endforeach;?>
								</select>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_hilight_on_home');?></th>
							<td>
								<input type="radio" name="is_show_hilight_on_home" value="1" <?php echo ($dataResult->is_show_hilight_on_home == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hilight_on_home" value="0" <?php echo ($dataResult->is_show_hilight_on_home == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>						
<!--						<tr>
							<th scope="row"><?php echo lang('is_show_display_on_home');?></th>
							<td>
								<input type="radio" name="is_show_display_on_home" value="1" <?php echo ($dataResult->is_show_display_on_home == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_display_on_home" value="0" <?php echo ($dataResult->is_show_display_on_home == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_hilight_bhs');?></th>
							<td>
								<input type="radio" name="is_show_hilight_bhs" value="1" <?php echo ($dataResult->is_show_hilight_bhs == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hilight_bhs" value="0" <?php echo ($dataResult->is_show_hilight_bhs == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_hilight_concert');?></th>
							<td>
								<input type="radio" name="is_show_hilight_concert" value="1" <?php echo ($dataResult->is_show_hilight_concert == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hilight_concert" value="0" <?php echo ($dataResult->is_show_hilight_concert == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_hilight_interview');?></th>
							<td>
								<input type="radio" name="is_show_hilight_interview" value="1" <?php echo ($dataResult->is_show_hilight_interview == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hilight_interview" value="0" <?php echo ($dataResult->is_show_hilight_interview == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_hilight_mv');?></th>
							<td>
								<input type="radio" name="is_show_hilight_mv" value="1" <?php echo ($dataResult->is_show_hilight_mv == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_hilight_mv" value="0" <?php echo ($dataResult->is_show_hilight_mv == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>-->	
						<tr>
							<th scope="row"><?php echo lang('is_show_new_released');?></th>
							<td>
								<input type="radio" name="is_show_new_released" value="1" <?php echo ($dataResult->is_show_new_released == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_new_released" value="0" <?php echo ($dataResult->is_show_new_released == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_recommend');?></th>
							<td>
								<input type="radio" name="is_show_recommend" value="1" <?php echo ($dataResult->is_show_recommend == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_recommend" value="0" <?php echo ($dataResult->is_show_recommend == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
<!--						<tr>
							<th scope="row"><?php echo lang('is_show_video_hit');?></th>
							<td>
								<input type="radio" name="is_show_video_hit" value="1" <?php echo ($dataResult->is_show_video_hit == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_video_hit" value="0" <?php echo ($dataResult->is_show_video_hit == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>	-->					
						<tr>
							<th scope="row"><?php echo lang('letters');?></th>
							<td><input type="text" name="letters" id="letters" class="small-text" maxlength="1" value="<?php echo $dataResult->letters;?>"/></td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('video_name');?></th>
							<td><input type="text" name="video_name" id="video_name" class="regular-text" value="<?php echo htmlspecialchars($dataResult->video_name, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('video_description');?></th>
							<td><?php echo display_ckeditor('video_description',''.$dataResult->video_description.'',array('toolbar' => 'Medium','skin' => 'v2','width' => '550px','height' => '200px'),false); ?></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('video_tag');?></th>
							<td><input type="text" name="video_tag" id="video_tag" class="regular-text" value="<?php echo htmlspecialchars($dataResult->video_tag, ENT_QUOTES, 'UTF-8');?>"/></td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('is_relate_song');?></th>
							<td>
								<input type="radio" name="is_relate_song" value="1" <?php echo ($dataResult->is_relate_song == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_relate_song" value="0" <?php echo ($dataResult->is_relate_song == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>							
						<tr class="is_relate_song" <?php echo ($dataResult->is_relate_song == 1 ? '':'style="display:none;"');?>>
							<th scope="row">
								<?php echo lang('song_relate');?>
								<a href="<?php echo base_url().'video/content_management/search_song';?>" class="tools plus search_tools">
								</a>
							</th>
							<td class="describe">
								<ul id="song_id" class="listItems">
									<?php
									if($dataResult->is_relate_song == '1') if(!empty($dataVideoSong)):?>
									<li class="first" style="display:none;">
										<?php echo lang('no_song_relate');?>
									</li>
									<?php
									foreach($dataVideoSong as $value):?>
									<li>
										<input type="checkbox" name="default_song_id[]" checked="checked" disabled="disabled"/>
										<?php echo $value->song_id.' - '.$value->song_name;?>
										<a
											href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);">
										</a><input type="hidden" name="song_id[]" value="<?php echo $value->song_id;?>" />
									</li>
									<?php endforeach;?>
									<?php
									else:?>
									<li class="first">
										<?php echo lang('no_song_relate');?>
									</li>
									<?php endif;?>
								</ul>
							</td>							
						</tr>
						<tr class="is_not_relate_song" <?php echo ($dataResult->is_relate_song == 0 ? '':'style="display:none;"');?>>
							<th scope="row">
								<?php echo lang('artist_relate');?>
								<a href="<?php echo base_url().'video/content_management/search_artist';?>" class="tools plus search_tools">
								</a>
							</th>
							<td class="describe">						
								<ul id="artist_id" class="listItems">
									<?php
									if($dataResult->is_relate_song == '0') if(!empty($dataVideoArtist)):?>
									<li class="first" style="display:none;">
										<?php echo lang('no_artist_relate');?>
									</li>
									<?php
									foreach($dataVideoArtist as $value):?>
									<li>
										<input type="checkbox" name="default_artist_id[]" value="<?php echo $value->artist_id;?>" <?php echo ($value->is_default == 1 ? 'checked="checked"':'');?>/>
										<?php echo $value->artist_id.' - '.$value->artist_name;?>
										<a
											href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);">
										</a><input type="hidden" name="artist_id[]" value="<?php echo $value->artist_id;?>" />
									</li>
									<?php endforeach;?>
									<?php
									else:?>
									<li class="first">
										<?php echo lang('no_artist_relate');?>
									</li>
									<?php endif;?>
								</ul>
							</td>
						</tr>
						<tr class="is_not_relate_song" <?php echo ($dataResult->is_relate_song == 0 ? '':'style="display:none;"');?>>
							<th scope="row">
								<?php echo lang('album_relate');?>
								<a href="<?php echo base_url().'video/content_management/search_album';?>" class="tools plus search_tools">
								</a>
							</th>
							<td class="describe">						
								<ul id="album_id" class="listItems">
									<?php
									if($dataResult->is_relate_song == '0') if(!empty($dataVideoAlbum)):?>
									<li class="first" style="display:none;">
										<?php echo lang('no_album_relate');?>
									</li>
									<?php
									foreach($dataVideoAlbum as $value):?>
									<li>
										<input type="checkbox" name="default_album_id[]" checked="checked" disabled="disabled"/>
										<?php echo $value->album_id.' - '.$value->album_name;?>
										<a
											href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);">
										</a><input type="hidden" name="album_id[]" value="<?php echo $value->album_id;?>" />
									</li>
									<?php endforeach;?>
									<?php
									else:?>
									<li class="first">
										<?php echo lang('no_album_relate');?>
									</li>
									<?php endif;?>
								</ul>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('video_image');?></th>
							<td>
								<?php
								if(!empty($dataResult->video_thumb_name)):?>
								<ul class="listImages">
									<li id="video_image_id_<?php echo $dataResult->video_id;?>">
										<div>
											<a href="<?php echo image_asset_url('../uploads/video/images/original/'.$dataResult->video_thumb_name.'.'.$dataResult->video_thumb_ext);?>" rel="gallery">
												<?php echo image_asset('../uploads/video/images/120x120/'.$dataResult->video_thumb_name.'.'.$dataResult->video_thumb_ext,'',array('width' => 120,'height'=> 120));?>
											</a>
										</div>
										<a href="javascript:void(0);" title="<?php echo image_asset_url('../uploads/video/images/original/'.$dataResult->video_thumb_name.'.'.$dataResult->video_thumb_ext);?>" onmouseOver="javascript:toClipboard(this)" class="tools wishlist"></a>
									</li>
								</ul>
								<?php endif;?>
								<input type="file" name="file_upload" id="file_upload"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('video_embed');?></th>
							<td><textarea id="video_embed" name="video_embed" rows="5" class="regular-text"><?php echo $dataResult->video_embed;?></textarea></td>
						</tr>														
						<tr>
							<th scope="row"><?php echo lang('video_file');?></th>
							<td>
							
								<?php if($dataResult->video_file_name):?>
									<div>
										<iframe src="<?php echo base_url('video_player/'.$dataResult->video_id);?>" width="425" height="300" scrolling="no"></iframe><br />
										<a href="<?php echo base_url();?>video/content_management/ajax_delete_media/<?php echo $dataResult->video_id;?>?field[]=video_file_name&amp;field[]=video_file_ext" class="tools delete deleteImage response-links"></a>
									</div><br />
								<?php endif;?>
								<input type="file" name="file_upload2" id="file_upload2"/>
							</td>
						</tr>
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_edit');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->